﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Peekaboo2008.dao;
using Peekaboo2008.model;

namespace Peekaboo2008.view
{
    public partial class FormNhomHangHoa : Form
    {
        public FormNhomHangHoa()
        {
            InitializeComponent();
            NhomHangHoaLoad();
        }

        public void NhomHangHoaLoad() 
        {
            DataTable dt = NhomHangDAO.getAll();
            dgvNhomHang.DataSource = dt;
        }

        private void dgvNhomHang_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            FormNhomHangHoa formNhomHangHoa = this;
            NhomHangModel model = new NhomHangModel();
            model.Id = dgvNhomHang.CurrentRow.Cells["Id"].Value.ToString();
            model.MaNganhHang = dgvNhomHang.CurrentRow.Cells["maNganhHang"].Value.ToString();
            model.Ten =  dgvNhomHang.CurrentRow.Cells["ten"].Value.ToString();
            model.Thue = dgvNhomHang.CurrentRow.Cells["thue"].Value.ToString();
            model.ChietKhau = dgvNhomHang.CurrentRow.Cells["chietKhau"].Value.ToString();
            model.GhiChu = dgvNhomHang.CurrentRow.Cells["ghiChu"].Value.ToString();
            FormChiTietNhomHangHoa formChiTietNHH = new FormChiTietNhomHangHoa(model, ref formNhomHangHoa);
            formChiTietNHH.ShowDialog();
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {
            FormNhomHangHoa formNhomHang = this;
            FormChiTietNhomHangHoa formChiTietNhomHang = new FormChiTietNhomHangHoa(ref formNhomHang);
            formChiTietNhomHang.ShowDialog();
        }

        private void FormNhomHangHoa_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormNhomHangHoa_KeyDown);
        }

        private void FormNhomHangHoa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                tsbThem.PerformClick();
            }
            else if(e.KeyCode == Keys.F4)
            {
                tsbThoat.PerformClick();
            }
        }

        private void tsbThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
